<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let arr = []
      for (let i = 0; i < 5; i++) {
        let num = +prompt(`请输入第${i + 1}个有效年龄`)
        if (num >= 1 && num <= 100) {
          arr.push(num)
        }
      }
      console.log(arr)
      for (let i = 0; i < arr.length; i++) {
        if (arr[i] >= 18) {
          document.write(`已经成年的年龄是${arr[i]}<br>`)
        }
      }

      let sum = 0
      for (let i = 0; i < arr.length; i++) {
        sum += arr[i]
      }
      document.write(`所有年龄的总和是${sum}<br>`)
      let ave = 0
      ave = sum / 5
      document.write(`所有年龄的平均数是${ave}<br>`)
      let max = arr[0]
      let min = arr[0]
      for (i = 1; i < arr.length; i++) {
        if (max < arr[i]) {
          max = arr[i]
        }
        if (min > arr[i]) {
          min = arr[i]
        }
      }
      document.write(`所有年龄的最大值是${max}<br>`)
      document.write(`所有年龄的最小值是${min}<br>`)
    </script>
  </body>
</html>
